<?php
class ModelWpFeedback extends Model {



    public function getList($customer_id,$pageNum = 0,$pageSize = 10000){
        $sql = "select a.*,b.image from wp_comments a left join customer b on a.user_id = b.customer_id  where comment_type= {$customer_id} order by comment_date";

        if (isset($pageNum) || isset($pageSize)) {
            if ($pageNum< 0) {
                $pageNum = 0;
            }

            if ($pageSize < 1) {
                $pageSize = 20;
            }

            $sql .= " LIMIT " . (int)($pageNum*$pageSize) . "," . (int)$pageSize;
        }



        $query = $this->db->query($sql);

        return $query->rows;
    }

    public function unReadCount($customer_id){
        $sql = "select count(*) count from wp_comments where `is_read` = 0 and comment_type={$customer_id}";

        $query = $this->db->query($sql);

        return $query->row['count'];
    }


    public function setFeedbackRead($customer_id){
        $sql = "update wp_comments set `is_read` = 1 where comment_type={$customer_id}";

        $query = $this->db->query($sql);
    }


    public function feedback($message,$sender_id,$sender_name){
        $sql = "insert into wp_comments 
		set comment_post_ID=0,
		comment_author='{$sender_name}',
		comment_date=CURRENT_TIMESTAMP,
		comment_date_gmt=CURRENT_TIMESTAMP, 
		comment_approved=1,
		comment_parent=0,
		comment_type={$sender_id},
		user_id={$sender_id},
		comment_content='{$message}',
		is_read = 1";


        $query = $this->db->query($sql);


    }
}